Add some minor defensive coding/error handling in xc_vmx_build.c like
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 10 Nov 2005 11:06:50 +0000 (12:06 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 10 Nov 2005 11:06:50 +0000 (12:06 +0100)
C/S 7687

Signed-off-by: Haifeng Xue <haifeng.xue@intel.com>
Signed-off-by: Xin Li <xin.b.li@intel.com>
tools/libxc/xc_vmx_build.c

index c81346558f2d668177e4c7bdac62d9a37dc4852b..f22d7ece4cebf315c811e4fec003e52e07b9e663 100644 (file)
@@ -565,8 +565,10 @@ static int setup_guest(int xc_handle,
     return 0;
 
  error_out:
-    free(mmu);
-    free(page_array);
+    if ( mmu != NULL )
+        free(mmu);
+    if ( page_array != NULL )
+        free(page_array);
     return -1;
 }
 
@@ -627,7 +629,7 @@ int xc_vmx_build(int xc_handle,
 
     if ( mlock(&st_ctxt, sizeof(st_ctxt) ) )
     {
-        PERROR("xc_vmx_build: ctxt mlock failed");
+        PERROR("%s: ctxt mlock failed", __func__);
         return 1;
     }
 
@@ -661,7 +663,8 @@ int xc_vmx_build(int xc_handle,
         goto error_out;
     }
 
-    free(image);
+    if ( image != NULL )
+        free(image);
 
     ctxt->flags = VGCF_VMX_GUEST;
     /* FPU is set up to default initial state. */
@@ -707,7 +710,8 @@ int xc_vmx_build(int xc_handle,
     return rc;
 
  error_out:
-    free(image);
+    if ( image != NULL )
+        free(image);
 
     return -1;
 }